package basededatos;
import java.sql.DriverManager;
import java.sql.ResultSet;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class ConexionBD {
	final String url = "jdbc:mysql://localhost:3306/GRUPO_3_DB?autoReconnect=true&useSSL=false";
	final String driver = "com.mysql.jdbc.Driver";
	final String usr = "root";
	final String pwd = "--cantaluppi-";
	private Connection conexion = null;
	
	
	public void Abrir(){
	
		if (conexion != null)
            return;
		
        try
        {
        	DriverManager.registerDriver(new com.mysql.jdbc.Driver()); 
            conexion = (Connection) DriverManager.getConnection(url, usr, pwd);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
	}
	
	
	public void Cerrar()
    {
        try{
            conexion.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
	
	
	public ResultSet RealizarConsulta(String consulta)
    {
        ResultSet rs = null;
        try
        {
            Statement s = (Statement) conexion.createStatement();

            rs = s.executeQuery(consulta);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return rs;
    }
	

	public Connection getConexion() {
		return conexion;
	}


}
